home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7704 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.tu-chemnitz.de!news
  2. From: hfst@hrz.tu-chemnitz.de (Hans Steffani)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: about free()
  5. Date: 28 Feb 96 10:07:43 GMT
  6. Organization: University of Technology Chemnitz, FRG
  7. Message-ID: <4h19na$3vh@pyrrhus-f.hrz.tu-chemnitz.de>
  8. References: <31333454.167E@mashie.ece.jhu.edu>
  9. NNTP-Posting-Host: sisyphus.hrz.tu-chemnitz.de
  10.  
  11. Chenyang Xu <chenyang@mashie.ece.jhu.edu> writes:
  12.  
  13. >Hi, there,
  14.  
  15. >     I have a simple question here.
  16.  
  17. >     I have a function say newarrary() which mallocs an array inside and
  18. >returns a pointer to this arrary. In another function foo.c, the result
  19. >of newarray() is assigned to a pointer ptr. Now after some operations on
  20. >this array. I use free(ptr) to free the memory allocated by newarrary().
  21. >My question is whould this cause a problem, since free() is not freeing
  22. >the same pointer which is allocated by the malloc() although this
  23. >pointer point to the same memory.
  24.  
  25. ptr = malloc( king_size );
  26. other_ptr = ptr;
  27.  
  28. then 
  29.  if( ptr != NULL ) free( ptr );
  30. is the same as
  31.  if( other_ptr != NULL ) free( other_ptr );
  32.  
  33. The function foo() is called by value as all c-functions.
  34. This means, it gets the value of its argument to process
  35. which is the same for ptr and other_ptr.
  36.  
  37. hope that helps
  38.  
  39. h.f.s.
  40.  
  41. --
  42. Hans Friedrich Steffani
  43. Institut fuer Elektrische Maschinen und Antriebe
  44. TU Chemnitz-Zwickau
  45. e-mail: hans.steffani@e-technik.tu-chemnitz.de
  46.